<template>
	<view class="pagecon">
		<head-box></head-box>
			<view class="page_mian tab-botton">
				<view class="banner">
					<image src="/static/img/zzly_banner.png" mode="aspectFill"></image>
				</view>
				<view class="zzly_tile_list">
					<view :class="panduan ? 'zzly_title lbor xz' : 'zzly_title lbor'" @tap="chegeType(true)">
						我要发布
					</view>
					<view :class="!panduan ? 'zzly_title rbor xz' : 'zzly_title rbor'" @tap="chegeType(false)">
						点击查看
					</view>
				</view>
				<view class="litem_list">
					<view v-if="panduan">
						<view class="personalInfor-page-main">
							<view class="personalInfor-page-main-box">
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>组织名称</text></view>
									<view class="_main-item-chunk _main-item-val">
										 <input cursorSpacing="10" class="_main-item-val-input" type="text" placeholder="请输入单位或组织名称" v-model="OrganizationName"/>
										<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
									</view>
								</view>
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>活动总人数</text></view>
									<view class="_main-item-chunk _main-item-val">
										 <input cursorSpacing="10" class="_main-item-val-input" type="number" placeholder="请输入活动总人数" v-model="maxnum"/>
										人
									</view>
								</view>
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>我方男生人数</text></view>
									<view class="_main-item-chunk _main-item-val">
										 <input cursorSpacing="10" class="_main-item-val-input" type="number" placeholder="请输入男生人数" v-model="Miannum"/>
										人
									</view>
								</view>
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>我方女生人数</text></view>
									<view class="_main-item-chunk _main-item-val">
										 <input cursorSpacing="10" class="_main-item-val-input" type="number" placeholder="请输入女生人数" v-model="Womannum"/>
										人
									</view>
								</view>
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>行业类别</text></view>
									<view class="_main-item-chunk _main-item-val">
										 <input cursorSpacing="10" class="_main-item-val-input" type="text" placeholder="请输入您组织的行业类别" v-model="HyType"/>
										<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
									</view>
								</view>
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>意向联谊行业</text></view>
									<view class="_main-item-chunk _main-item-val">
										 <input cursorSpacing="10" class="_main-item-val-input" type="text" placeholder="请输入意向联谊行业" v-model="YxType"/>
										<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
									</view>
								</view>
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>承办方</text></view>
									<view class="_main-item-chunk _main-item-val">
										<picker class="_main-item-val-input" @change="changetype1" :value="moveTypeIndex" :range="chooseTypeArr" >
											<view class="uni-input _main-item-val-input-text">
												{{chooseTypeArr[moveTypeIndex]}}
												<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
											</view>
										</picker>
									</view>
								</view>
								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>经费承担</text></view>
									<view class="_main-item-chunk _main-item-val">
										<picker class="_main-item-val-input" @change="changetype2" :value="JfTypeIndex" :range="JfTypeArr" >
											<view class="uni-input _main-item-val-input-text">
												{{JfTypeArr[JfTypeIndex]}}
												<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
											</view>
										</picker>
									</view>
								</view>

								<view class="_main-item" >
									<view class="_main-item-chunk _main-item-label"><text>办公电话</text></view>
									<view class="_main-item-chunk _main-item-val">
										 <input cursorSpacing="10" class="_main-item-val-input" maxlength="11" type="text" placeholder="请输入您的办公电话" v-model="Phone"/>
										<image class="drop-dowm-img" src="../../static/img/drop-down.png" mode=""></image>
									</view>
								</view>

							</view>
						</view>
						<view>
							<textarea class="textarea" v-model="advice" placeholder="请输入组织联谊的 时间 , 地点 等信息"></textarea>
						</view>
						<view class="subbtn">
							<button type="primary"  @click="SubmitMessage">发布</button>
						</view>
					</view>
					<view v-if="!panduan">
						<z-paging ref="paging" @query="queryList" :usePageScroll="true" :list.sync="list"  style="height: 110%;">
							<view class="box2"  v-for="(item, index) in list" :key="index">
								<view class="item_box">
									<view class="item1">
										<image :src="item.userPic == '' ? '../../static/img/logob.png' : item.userPic" mode="aspectFill"></image>
									</view>
									<view class="item">
										<view class="item_b">
											{{GetShortName(item.userNickname)}}
										</view>
										<view class="item_c">
											<text>{{item.adviseContent}}</text>
										</view>
										<view class="item_d">
											<view class="item_e">{{item.createTime}}</view>
											<view class="item_f" v-if="item.phone != ''"><button  @tap="makePhoneCall(item.phone)" size="mini" type="warn">沟通</button></view>

										</view>
									</view>
								</view>
							</view>
						</z-paging>
					</view>
				</view>
			</view>
		<tabs-box></tabs-box>
	</view>
</template>

<script>
	import { gpUseradviseAlllist ,gpUseradvisesubmit} from '@/common/request.js';
	export default {
		data() {
			return {

				OrganizationName:'',
				Miannum:0,
				Womannum:0,
				maxnum:0,
				HyType:'',
				YxType:'',
				Phone:'',
				advice:'',					//详细描述
				chooseTypeArr: ['我方承办','双方共办','对方承办'],
				moveTypeIndex: 0,
				JfTypeArr: ['我方承担','双方共担','对方承担'],
				JfTypeIndex: 0,
				pageSize:20,
				pageNo:1,

				panduan:true,
				list: [],
			};
		},
		onLoad() {

			//this.date = this.getDate('start');
			//this.GetType();
			//this.getList();
		},
    onShow(){
      // #ifdef H5
      console.log('分享')
      this.$wxSetShare()
      // #endif
    },
		methods:{
			chegeType(e)
			{
				this.panduan = e;
			},
			changetype1(e) {
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.moveTypeIndex = e.target.value;
			},
			changetype2(e) {
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.JfTypeIndex = e.target.value;
			},
			SubmitMessage()
			{
				if(this.OrganizationName.length < 6)
				{
					this.$api.msg('请输入正确的组织名称!');
					return;
				}
				if(this.maxnum <= 0)
				{
					this.$api.msg('总人数必须大于0人');
					return;
				}
				if(this.Miannum + this.Womannum <= 0)
				{
					this.$api.msg('男生加女生的人数必须大于0人!');
					return;
				}

				if(this.HyType == "")
				{
					this.$api.msg('行业类别不能为空!');
					return;
				}

				if(this.YxType == "")
				{
					this.$api.msg('意向联谊行业不能为空!');
					return;
				}

				if(this.Phone.length < 8)
				{
					this.$api.msg('手机号码不正确!');
					return;
				}

				let message = "组织名称："+this.OrganizationName;
				message += "\r\n活动总人数："+this.maxnum + "人";
				message += "\r\n我方男生人数："+this.Miannum + "人";
				message += "\r\n我方女生人数："+this.Womannum + "人";
				message += "\r\n行业类别："+this.HyType ;
				message += "\r\n意向联谊行业："+this.YxType;
				message += "\r\n承办方："+ this.chooseTypeArr[this.moveTypeIndex];
				message += "\r\n经费承担："+ this.JfTypeArr[this.JfTypeIndex];
				message += "\r\n联系电话："+this.Phone;
				message += "\r\n额外描述：\r\n"+this.advice;

				console.log(message);
				//if(!uni.getStorageSync("token"))
				//{
				//	this.$api.msg('请先登录!!');
				//	return;
				//}
				var params ={"adviseContent": message,"useradviseType":"8"}
				console.log(params);
				gpUseradvisesubmit(params).then(res => {
					console.log(res)

					if(res.success)
					{
						this.$api.msg('提交成功');
						this.advice = '';
						this.chegeType(false);
					}
				});
			},
			queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				this.pageSize=pageSize;
				this.pageNo=pageNo;
				this.getList()
			},
			getList()
			{
				var that = this
				let params = {"useradviseType":"8","adviseStatus":"3","column": "createTime","order": "desc"}
				gpUseradviseAlllist(that.pageSize,that.pageNo,params).then(res => {

					if(res.success)
					{
						console.log(res.result)
						that.list = []
						res.result.records.forEach(ele => {
							//console.log(ele);
							let con = ele.adviseContent.replace(/\r/g,'').replace(/\n/g,'');
							con = this.getStr(con,"联系电话：","额外描述")

							ele["phone"] = con;
							console.log(ele);
							that.list.push(ele);
							that.$refs.paging.complete(that.list);
						});

					}
				});
			},
			GetShortName(username){
				if(username == undefined)
					return "";
				if(username.length>7)
					return username.substring(0,7)+"****";
				else
					return username;
			},
			getStr(str, start, end) {
			    let res = str.match(new RegExp(`${start}(.*?)${end}`))
			    return res ? res[1] : ""
			},
			makePhoneCall(phone){
				uni.makePhoneCall({
				    phoneNumber: phone
				});
			},
		}
	}
</script>

<style lang="scss">
.pagecon{
		height: 100vh;
		.page_mian{
			padding: 30rpx;
			.banner{
				width: 100%;
				height: 280rpx;
				margin-bottom: 30rpx;
				image{
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}
			}

			.quntuanListPage-main-title{
				font-size: 32rpx;
				color: #333;
				font-weight: 600;
				border-left: 6rpx solid #0071fc;
				background-image:linear-gradient(left, #eff6ff, #ffffff);
				padding-left: 20rpx;
			}

			.textarea{
				border-radius: 10rpx;
				border: 1px solid #cccccc;
				padding: 20rpx;
				width: 100%;
				margin-top: 50rpx;
			}
			.subbtn{
				margin-top: 50rpx;
			}
		}

		.personalInfor-page-main{
			width: 100%;
			box-sizing: border-box;
			margin-top: 20rpx;
			.personalInfor-page-main-box{
				width: 100%;
				._main-item{
					// height: 86rpx;
					border-bottom: 1px solid rgba(200,199,204,0.5);
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
					align-items: center;
					._main-item-chunk{
						font-size: 34rpx;
						color: #000;
						line-height: 84rpx;
					}
					._main-item-label{
						width: 30%;
					}
					._main-item-val{
						width: 70%;
						display: flex;
						flex-wrap: nowrap;
						justify-content: flex-end;
						align-items: center;
						._main-item-val-head{
							width: 48rpx;
							height: 48rpx;
							border-radius: 50%;
							display: flex;
							.head-img{
								width: 100%;
								height: 100%;
								border-radius: 50%;
							}
						}
						._main-item-val-input{
							text-align: right;
							display: flex;
							._main-item-val-input-text{
								display: flex;
								flex-wrap: nowrap;
								align-items: center;
							}
							.drop-dowm-img{
								width: 30rpx;
								height: 30rpx;
								margin-left: 10rpx;
								transform: rotateZ(270deg);
							}
						}
						.drop-dowm-img{
							width: 30rpx;
							height: 30rpx;
							margin-left: 10rpx;
							transform: rotateZ(270deg);
						}
					}
				}

			}
		}

		.zzly_tile_list{
			display: flex;
			flex-direction: row;
			.zzly_title{
				width: 50%;
				text-align: center;
				padding: 20rpx 0;
				background-color: #f7f7f7;
				border: 1rpx solid #cccccc;
			}
			.xz{
				background-color: #007aff;
				color: #ffffff;
				border: 1rpx solid #007aff;
			}
			.lbor{
				border-radius: 10rpx 0 0 10rpx;
			}
			.rbor{
				border-radius:  0 10rpx 10rpx  0;
			}
		}
	}
	.box2{
		margin: 0 30rpx;
		padding: 0 30rpx;
		border-bottom: 1px solid #bbbbbb;
		.item_box{
			display: flex;
			flex-direction: row;
			.item1{
				padding: 30rpx 30rpx 0 0;
				width: 110rpx;
				image{
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}
			}
			.item{
				width: calc(100% - 110rpx);
				padding: 30rpx 0;
				.item_b{
					text-align: left;
					font-size: 30rpx;
					font-weight: bold;
				}
				.item_c{
					font-size: 24rpx;
					line-height: 40rpx;
					margin-top: 20rpx;
					/*color: #888888;
					text-indent: 2em;*/
				}
				.item_d
				{
					display: flex;
					flex-direction: row;
					.item_e{
						color: #bbbbbb;
						font-size: 24rpx;
						margin-top: 20rpx;
						width: calc(100% - 130rpx) ;
					}
					.item_f{
						width: 130rpx;
					}

				}
			}
		}
	}
</style>
